from typing import List


class Solution:
    def fillCups(self, amount: List[int]) -> int:
        count = 0
        maxVal = max(amount)
        while maxVal > 0:
            maxIndex = 0
            for i in range(3):
                if amount[i] == maxVal:
                    maxIndex = i
                    break

            amount[maxIndex] -= 1
            for i in range(3):
                if maxIndex != i and amount[i] > 0:
                    amount[i] -= 1
                    break
            count += 1
            maxVal = max(amount)

        return count

    def fillCups2(self, amount: List[int]) -> int:
        count = 0
        while True:
            amount.sort()
            if amount[2] == 0:
                break
            amount[2] -= 1
            amount[1] = amount[1]-1 if amount[1] > 0 else 0
            count += 1

        return count

    def fillCups3(self, amount: List[int]) -> int:
        amount.sort()
        if amount[2] > amount[1] + amount[0]:
            return amount[2]
        return (sum(amount) + 1) // 2


print(Solution().fillCups3([5, 4, 4]))
